// pages/server/sign/index.js
const app = getApp()
const handler = require("../../../style/function.js")
let img = handler.userImg;
Page({
  data: {
    dateArr: [],
    monthArr: [],
    sign:{
      isSign: false, // 签到状态
      day: 0,
      get_win: [
        { title: '10天', grow_point: 40, status: true },
        { title: '30天', grow_point: 50, status: true }
      ]
    },
    imgUrl: handler.serverImg,//图片路径引入
  },
  onLoad: function () {
  },
  //签到按钮
  signIn: function () {
    let that = this;
    const { sign}=this.data;
    // 重置签到状态
    wx.showModal({
      content: '已签到',
      duration:5000,
      showCancel:false,
      success:function(){
        sign.isSign = true;
        ++sign.day;
        that.setData({
          sign
        });
        handler.redirectTo("../member/index?status=true")
      },
    })
  },
  onShow: function (options) {
    let date=new Date();
    let years = date.getFullYear();
    let months = date.getMonth() + 1;
    let days = date.getDate();
    let that=this;
    handler.calendarHandler(years, months,res=>{
      console.log(res)
      that.setData({
        dateArr: {
          year: res.dateArr.year,
          month: res.dateArr.month
        },
        monthArr: res.monthArr,
      })
    })
    this.get_data(years, months);
  },
  // 倒退时间
  data_left_handler:function(){
    const { dateArr}=this.data;
    if (dateArr.month>1){
      --dateArr.month;
    }else{
      --dateArr.year;
      dateArr.month=12;
    }
   
    this.get_data(dateArr.year, dateArr.month);
    this.setData({ dateArr})
  },
  // 前进时间
  data_right_handler:function(){
    const { dateArr } = this.data;
    if (dateArr.month <12) {
      ++dateArr.month;
    } else {
      ++dateArr.year;
      dateArr.month = 1;
    }
    this.get_data(dateArr.year, dateArr.month);
    this.setData({ dateArr })
  },
  //获取时间数据
  get_data: function (year,month){
    let that = this;
    handler.calendarHandler(year, month, res => {
      console.log(res)
      that.setData({
        dateArr: {
          year: res.dateArr.year,
          month: res.dateArr.month
        },
        monthArr: res.monthArr,
      })
    })
  },
  get_win:function(e){
    var id=e.currentTarget.dataset.id;
    const {sign}=this.data;
    var that=this;
    wx.showModal({
      content: '恭喜你获取奖励',
      showCancel: false,
      success:function(){
        sign.get_win[id].status = false;
        that.setData({ sign})
      } 
    })
    
  },
})